<template>
	<view>
		<view class="header">
			<view class="header-font">
				<view class="hellow">
					您好,
				</view>
				<view class="welcome">
					欢迎登录车联网服务
				</view>
			</view>
			<image src="/static/组 6.png" mode=""></image>
		</view>
		<view class="container">
			<view class="">
				<input type="text" v-model="mobile" placeholder="手机号登录" />
			</view>
			<view class="">
				<input type="text" v-model="verifyCode" placeholder="验证码登录" />
			</view>
			<button class="verification" @click="setTimer">{{timeText}}</button>
			<button class="login" @click="login">登录</button>
		</view>
		<view class="location">
			<view class="title">
				获取你的位置信息
			</view>
			<view class="introduction">
				你的位置信息将用于获取你附近的站点
			</view>
			<view class="btn">
				<button class="reject">拒绝</button>
				<button class="accpet">允许</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				verifyCode: '',
				verifyCodeToken: '',
				mobile: '',
				timer: '',
				timeRemaining: -1,
				timeText: '获取验证码'
			}
		},
		mounted() {
			
		},
		methods: {
			getCode() {
				uni.request({
					url: `${this.$cfuserBaseUrl}/getCode`,
					method: 'GET',
					success: (res) => {
						let data = res.data
						this.verifyCodeToken = data.msg
						uni.showToast({
							icon: 'success',
							title: '发送成功'
						})
					}
				})
			},
			setTimer() {
				if (this.mobile == '') {
					uni.showToast({
						icon: 'error',
						title: '请输入正确的手机号码'
					})
					return
				}
				if (this.timeRemaining != -1) {
					return
				}
				this.getCode()
				this.timeRemaining = 59;
				this.timer = setInterval(() => {
					this.timeText = '已发送(' + this.timeRemaining-- + ')'
					if (this.timeRemaining == -1) {
						this.timeText = '获取验证码'
						clearInterval(this.timer)
					}
				}, 1000)
			},
			login() {
				uni.request({
					url: `${this.$cfuserBaseUrl}/login`,
					method: 'POST',
					data: {
						mobile: this.mobile,
						verifyCode: this.verifyCode,
						verifyCodeToken: this.verifyCodeToken
					},
					success: (res) => {
						console.log(res)
						let data = res.data
						if (data.code != 200) {
							uni.showToast({
								icon: 'error',
								title: '验证码错误'
							})
						} else {
							uni.showToast({
								icon: 'success',
								title: '登陆成功!'
							})
							uni.setStorageSync('token', data.data.access_token)
							uni.setStorageSync('cfuser', data.data.cfuser)
							uni.reLaunch({
								url: '/pages/index/index'
							})
						}
						
					}
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: #FFFFFF;
	}
	.header {
		background-image: url('/static/组 8.png');
		height: 400rpx;
	}
	
	.header-font {
		position: absolute;
		left: 100rpx;
		top: 160rpx;
	}
	
	.hellow {
		font-size: 50rpx;
		color: #FFFFFF;
		margin-bottom: 20rpx;
	}
	
	.welcome {
		font-size: 32rpx;
		color: #FFFFFF;
	}
	
	.header > image {
		width: 300rpx;
		height: 250rpx;
		position: absolute;
		right: 50rpx;
		top: 150rpx;
		z-index: 100;
	}
	
	.container {
		padding: 100rpx 80rpx 0 80rpx;
		background-color: #FFFFFF;
		position: relative;
		bottom: 80rpx;
		border-top-right-radius: 80rpx;
		border-top-left-radius: 80rpx;
	}
	
	.container > view {
		margin-top: 50rpx;
		border-bottom: 1rpx solid #c7c9ce;
		opacity: 0.5;
		padding-left: 30rpx;
		padding-bottom: 10rpx;
	}
	
	.verification {
		font-size: 28rpx;
		line-height: 60rpx;
		width: 200rpx;
		height: 60rpx;
		border-radius: 50rpx;
		background-color: #4C8EFE;
		color: #FFFFFF;
		position: absolute;
		right: 80rpx;
		bottom: 150rpx;
	}
	
	.login {
		background-color: #0762E6;
		color: #FFFFFF;
		border-radius: 50rpx;
		margin-top: 50rpx;
	}
	
	.location {
		box-shadow: 0px 0px 10px 0px;
		position: absolute;
		bottom: 0;
		height: 300rpx;
		width: 710rpx;
		padding: 30rpx 0 0 40rpx;
		border-top-right-radius: 50rpx;
		border-top-left-radius: 50rpx;
	}
	
	.title {
		font-weight: bold;
	}
	
	.introduction {
		font-size: 16rpx;
		margin-top: 20rpx;
	}
	
	.btn > button {
		color: #FFFFFF;
		width: 240rpx;
		height: 60rpx;
		line-height: 60rpx;
		margin: 0;
		font-size: 16rpx;
	}
	
	.btn {
		margin-top: 40rpx;
		display: flex;
		justify-content: space-between;
		padding-right: 40rpx;
	}
	
	.reject {
		
		background-color: #b9b9b9;
	}
	
	.accpet {
		background-color: #4C8EFE;
	}
</style>